import LevelInitBase from "../LevelCommon/LevelInitBase";
import LevelControl4 from "../LevelControl/LevelControl4";
import RoomControl from "../LevelCommon/RoomControl";
import { utils } from "../../utils/CommonUtil";
import CallToLevel from "../Prefabs/CallToLevel";
import RotateObj from "../Prefabs/InteractivObj/Common/RotateObj";
import GamePropObj from "../Prefabs/InteractivObj/Common/GamePropObj";
import FocusMoreParentObj from "../Prefabs/InteractivObj/Common/FocusMoreParentObj";
import FocusParentObj from "../Prefabs/InteractivObj/Common/FocusParentObj";
import PhysPassLock from "../Prefabs/InteractivObj/PhysPassLock/PhysPassLock";
import PhysPassKey from "../Prefabs/InteractivObj/PhysPassLock/PhysPassKey";
import ArtBoard from "../Prefabs/InteractivObj/ArtBoard";
import Gate from "../Prefabs/InteractivObj/Gate";
import EnumData from "../../Enum/EnumData";
import PasswordLock from "../Prefabs/InteractivObj/Password/PasswordLock";
import PasswordKey from "../Prefabs/InteractivObj/Password/PasswordKey";
import MoveObj from "../Prefabs/InteractivObj/Common/MoveObj";

export default class LevelInit4 extends LevelInitBase {
    private room1: Laya.Sprite3D;
    private room2: Laya.Sprite3D;

    private container: Laya.Sprite3D;

    public startInitDetail() {
        this.levelRoot.addComponent(LevelControl4);
        this.room1 = this.LevelObjs.getChildByName("room1") as Laya.Sprite3D;
        this.room1.addComponent(RoomControl);
        this.room2 = this.LevelObjs.getChildByName("room2") as Laya.Sprite3D;
        this.room2.addComponent(RoomControl);
        this.container = this.room1.getChildByName("Container") as Laya.Sprite3D;

        //#region Room1 Container
        let Container = this.room1.getChildByName("Container") as Laya.Sprite3D;
        let Ladder = Container.getChildByName("Ladder") as Laya.Sprite3D;
        let CallToLevel_Ladder = utils.CommonUtils.CustomAddComponent(Ladder, CallToLevel);

        let Pallet_props = Container.getChildByName("Pallet_props") as Laya.Sprite3D;
        let RotateObj_Pallet_props = utils.CommonUtils.CustomAddComponent(Pallet_props, RotateObj) as RotateObj;
        RotateObj_Pallet_props.targetRotate = new Laya.Vector3(0, 180, 25);
        RotateObj_Pallet_props.rotateTime = 500;
        RotateObj_Pallet_props.VoiceName = "openGate";
        RotateObj_Pallet_props.IsRotateOnce = true;

        let checkFocus =  Pallet_props.getChildByName("checkFocus") as Laya.Sprite3D;
        utils.CommonUtils.CustomAddComponent(checkFocus,FocusMoreParentObj);

        let tie_lock_room1 =  checkFocus.getChildByName("tie_lock_room1") as Laya.Sprite3D;
        utils.CommonUtils.CustomAddComponent(tie_lock_room1,CallToLevel);

        let button_5 = Container.getChildByName("button_5") as Laya.Sprite3D;
        let GamePropObj_button_5 = utils.CommonUtils.CustomAddComponent(button_5, GamePropObj) as GamePropObj;
        GamePropObj_button_5.gamePropId = 18;

        let Door_panel = Container.getChildByName("Door_panel") as Laya.Sprite3D;
        let RotateObj_Door_panel = utils.CommonUtils.CustomAddComponent(Door_panel, RotateObj);
        RotateObj_Door_panel.targetRotate = new Laya.Vector3(0, 0, 90);
        RotateObj_Door_panel.rotateTime = 800;
        RotateObj_Door_panel.IsRotateOnce = true;
        RotateObj_Pallet_props.VoiceName = "openGate";

        let Pew_props = Container.getChildByName("Pew_props") as Laya.Sprite3D;
        let FocousMoreParentObj_Pew_props = utils.CommonUtils.CustomAddComponent(Pew_props, FocusMoreParentObj);

        let physPassLock = Pew_props.getChildByName("physPassLock") as Laya.Sprite3D;
        utils.CommonUtils.CustomAddComponent(physPassLock, FocusParentObj);
        let PhysPassLock_physPassLock = utils.CommonUtils.CustomAddComponent(physPassLock, PhysPassLock) as PhysPassLock;
        PhysPassLock_physPassLock.isDestroyEnd = true;
        PhysPassLock_physPassLock.correctPassInde.push(2);
        PhysPassLock_physPassLock.correctPassInde.push(0);
        PhysPassLock_physPassLock.correctPassInde.push(1);

        let physPassLockChildNum = physPassLock.numChildren;
        for (let index = 0; index < physPassLockChildNum; index++) {
            let child = physPassLock.getChildAt(index);
            let PhysPassKey_child = utils.CommonUtils.CustomAddComponent(child, PhysPassKey) as PhysPassKey;
            PhysPassKey_child.rotateAngle = 45;
        }

        utils.CommonUtils.CustomAddComponent(Container.getChildByName("Plane001"), FocusMoreParentObj);
        utils.CommonUtils.CustomAddComponent(Container.getChildByName("Plane002"), FocusMoreParentObj);
        utils.CommonUtils.CustomAddComponent(Container.getChildByName("Plane003"), FocusMoreParentObj);

        let GameObject = Container.getChildByName("GameObject");
        utils.CommonUtils.CustomAddComponent(GameObject, FocusMoreParentObj);

        let Square_painting_props = GameObject.getChildByName("Square painting_props");
        (utils.CommonUtils.CustomAddComponent(Square_painting_props, GamePropObj) as GamePropObj).gamePropId = 17;

        //#endregion

        let room1Walls = this.room1.getChildByName("walls");
        //#region Room1 wall1
        let room1Wall1 = room1Walls.getChildByName("wall1");

        let paintings = room1Wall1.getChildByName("paintings");
        let paintingsChildNum = paintings.numChildren;
        for (let index = 0; index < paintingsChildNum; index++) {
            let child = paintings.getChildAt(index) as Laya.Sprite3D;
            utils.CommonUtils.CustomAddComponent(child, FocusParentObj);
            let artBoard = child.getChildByName("ArtBoard");
            let ArtBoard_artBoard = utils.CommonUtils.CustomAddComponent(artBoard, ArtBoard) as ArtBoard;
            switch (index) {
                case 0:
                    ArtBoard_artBoard.needGamePropid = 19;
                    break;
                case 1:
                    ArtBoard_artBoard.needGamePropid = 17;
                    break;
                case 2:
                    let Circle_painting_props = child.getChildByName("Circle painting_props");
                    (utils.CommonUtils.CustomAddComponent(Circle_painting_props,GamePropObj)as GamePropObj).gamePropId = 19;
                    ArtBoard_artBoard.needGamePropid = 20;
                    break;
            }
        }

        //#endregion

        //#region room1 wall2
        let room1Wall2 = room1Walls.getChildByName("wall2");     
        let door_props_room1 = room1Wall2.getChildByName("door_props_room1");    
        let Gate_door_props_room1 = utils.CommonUtils.CustomAddComponent(door_props_room1,Gate) as Gate;
        Gate_door_props_room1.Angle=20;
        Gate_door_props_room1.Axis = EnumData.Axis.Z;
        Gate_door_props_room1.isNeedCallToLevel = true;

        let windowBoxes = room1Wall2.getChildByName("windowBoxes");  
        let CallToLevel_windowBoxes = utils.CommonUtils.CustomAddComponent(windowBoxes,CallToLevel);
        let box_props_on = windowBoxes.getChildByName("box_props_on");  
        utils.CommonUtils.CustomAddComponent(box_props_on,CallToLevel);
        
        let jinianpin1 = room1Wall2.getChildByName("jinianpin (1)"); 
        let GamePropObj_jinianpin1 = utils.CommonUtils.CustomAddComponent(jinianpin1,GamePropObj) as GamePropObj;
        GamePropObj_jinianpin1.gamePropId =11;
        //#endregion

        //#region room1 wall3
        let room1Wall3 = room1Walls.getChildByName("wall3");  
        let Rectangle_painting_props = room1Wall3.getChildByName("Rectangle painting_props");  
        (utils.CommonUtils.CustomAddComponent(Rectangle_painting_props,GamePropObj) as GamePropObj).gamePropId = 20;
        //#endregion

        let jinianpin = this.room1.getChildByName("jinianpin");
        (utils.CommonUtils.CustomAddComponent(jinianpin,GamePropObj) as GamePropObj).gamePropId = 11;


        let room2walls = this.room2.getChildByName("walls");

        //#region room2wall2
        let room2wall2 = room2walls.getChildByName("wall2");
        let Battery_table =room2wall2.getChildByName("Battery table");
        utils.CommonUtils.CustomAddComponent(Battery_table,FocusParentObj);
        (utils.CommonUtils.CustomAddComponent(Battery_table.getChildByName("8"),GamePropObj) as GamePropObj ).gamePropId = 21;

        let Password_machine = room2wall2.getChildByName("Password machine");
        utils.CommonUtils.CustomAddComponent(Password_machine,FocusParentObj);

        let passwordLockRoom2 = Password_machine.getChildByName("passwordLockRoom2");
        let PasswordLock_passwordLockRoom2 = utils.CommonUtils.CustomAddComponent(passwordLockRoom2,PasswordLock) as PasswordLock;
        PasswordLock_passwordLockRoom2.passWord = "982375";

        let keyBoard = passwordLockRoom2.getChildByName("keyBoard") as Laya.Sprite3D;
        for (let index = 0; index < keyBoard.numChildren; index++) {
            let child = keyBoard.getChildAt(index);
            let passwordKey = utils.CommonUtils.CustomAddComponent(child, PasswordKey) as PasswordKey;
            if(child.name == "enter"){
                passwordKey.keyValue="enter"
            }else{
                passwordKey.keyValue = (index + 1) + "";
            }
        }

        let Broken_button_05 = Password_machine.getChildByName("Broken button_05");
        utils.CommonUtils.CustomAddComponent(Broken_button_05,CallToLevel);

        let Broken_button_08 = Password_machine.getChildByName("Broken button_08");
        utils.CommonUtils.CustomAddComponent(Broken_button_08,CallToLevel);
        
        let password_panel_props = Password_machine.getChildByName("password_panel_props");
        let RotateObj_password_panel_props = utils.CommonUtils.CustomAddComponent(password_panel_props,RotateObj) as RotateObj;
        RotateObj_password_panel_props.targetRotate = new Laya.Vector3(75,0,0);
        RotateObj_password_panel_props.rotateTime = 500;
        RotateObj_password_panel_props.IsRotateOnce = true;

        let Cylinder011= Password_machine.getChildByName("Cylinder011");
        (utils.CommonUtils.CustomAddComponent(Cylinder011,GamePropObj) as GamePropObj).gamePropId = 22;

        let jinianpin2 = room2wall2.getChildByName("jinianpin");
        (utils.CommonUtils.CustomAddComponent(jinianpin2,GamePropObj) as GamePropObj).gamePropId = 11;
        //#endregion

        ////#region  room2 wall4
        let room2wall4 = room2walls.getChildByName("wall4");
        let door_props_room2 = room2wall4.getChildByName("door_props_room2");
        let Gate_door_props_room2 = utils.CommonUtils.CustomAddComponent(door_props_room2,Gate) as Gate;
        Gate_door_props_room2.isNeedCallToLevel = true;
        Gate_door_props_room2.Angle = -20;
        Gate_door_props_room2.Axis = EnumData.Axis.Z;
        Gate_door_props_room2.needPropId = 0;

        let chair_props_room2 = room2wall4.getChildByName("chair_props_room2");
        let MoveObj_chair_props_room2 = utils.CommonUtils.CustomAddComponent(chair_props_room2,MoveObj) as MoveObj;
        MoveObj_chair_props_room2.isNeedCallToLevel = true;
        MoveObj_chair_props_room2.tweenTime = 500;
        MoveObj_chair_props_room2.VoiceName = "move";
        MoveObj_chair_props_room2.targetPos = new Laya.Vector3(-1.643,-0.044,-0.7670232);
        //#endregion
    }
}